package main

import (
	"free_convert/config"
	"free_convert/router"
	"free_convert/utils/logger"
	"path/filepath"
)

func main() {
	// Initalize global logger
	if err := logger.InitGlobalLogger(loggerConfig()); err != nil {
		panic(err)
	}
	defer logger.Sync()
	r := router.Router()
	defer func() {
		if err := recover(); err != nil {
			logger.Error("Caught exception", err)
		}
	}()

	r.Run(":8081")
}

func loggerConfig() logger.Config {
	cfg := logger.Config{
		Level:      logger.DebugLevel,
		Filename:   filepath.Join(config.LogDir, "app.log"),
		MaxSize:    100, // MB
		MaxBackups: 7,   // 保留7天
		MaxAge:     30,  // 保留30天
		Compress:   true,
		Console:    true,
	}
	return cfg
}
